import {Actor, Action} from 'iflux2';
import {GoodsType} from '../constant/action-type';


export default class GoodsActor extends  Actor {
    defaultState() {
        return {
            itemOrders: []
        }
    }


    @Action(GoodsType.SET_ITEM_ORDER)
    setOrders(state, itemOrders) {
        return state.set('itemOrders', itemOrders);
    }


    @Action(GoodsType.SET_NUM)
    changeNum(state, {num, index}) {
        return state.setIn(['itemOrders', index, 'itemNumber'], num);
    }


    @Action(GoodsType.SET_PRICE)
    changePrice(state, {price, type, index}) {
        const field = !type ? 'pervalue' : 'discount';
        return state.updateIn(['itemOrders', index], (item)=>item.set(field, price).set('type', type));
    }
}